package com.exposit.books.dao;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.exposit.books.domain.Book;

@Repository
@Transactional
public class BookDAOImpl extends AbstractDAOImpl<Book, Long> implements BookDAO  {

	@Override
	public Book getBookById(Long id) {
		Query q = getSession().createQuery("from Book where id = :id");
        q.setLong("id", id);
        return (Book) q.uniqueResult();
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Book> getBookByName(String name) {
		List<Book> elements = new ArrayList<Book>();
		Query q = getSession().createQuery("from Book where name = :name");
		q.setString("name", name);
		elements = q.list();	
		return elements;
	}

}
